import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/* Router Modules */
// import componentsRouter from './modules/components'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: '控制面板', icon: 'dashboard', affix: true }
      }
    ]
  }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  /** when your routing map is too long, you can split it into small modules **/
  // componentsRouter,
  // chartsRouter,
  // nestedRouter,
  // tableRouter,

  {
    path: '/admin/sys',
    component: Layout,
    alwaysShow: true,
    redirect: 'noRedirect',
    name: 'admin_sys',
    meta: {
      title: '系统设置',
      icon: 'el-icon-setting'
    },
    children: [
      {
        path: '/admin/area',
        component: () => import('@/views/area/index'),
        name: 'area',
        meta: { title: '区域管理', icon: 'el-icon-place' }
      }
    ]
  },
  {
    path: '/admin/student',
    component: Layout,
    redirect: 'noRedirect',
    name: 'admin_student',
    meta: {
      title: '教务管理',
      icon: 'peoples'
    },
    children: [
      {
        path: '/admin/grade',
        component: () => import('@/views/grade/index'),
        name: 'grade',
        meta: { title: '年级管理', icon: 'tree-table' }
      },
      {
        path: '/admin/major',
        component: () => import('@/views/major/index'),
        name: 'major',
        meta: { title: '专业管理', icon: 'el-icon-tickets' }
      },
      {
        path: '/admin/classs',
        component: () => import('@/views/classs/index'),
        name: 'classs',
        meta: { title: '班级管理', icon: 'el-icon-box' }
      },
      {
        path: '/admin/student',
        component: () => import('@/views/student/index'),
        name: 'student',
        meta: { title: '学生管理', icon: 'user' }
      }
    ]
  },
  {
    path: '',
    component: Layout,
    alwaysShow: false,
    redirect: 'noRedirect',
    name: 'admin_course',
    meta: {
      title: '课程资源',
      icon: 'education'
    },
    children: [
      {
        path: '/admin/category',
        component: () => import('@/views/category/index'),
        name: 'category',
        meta: { title: '分类管理', icon: 'list' /* , breadcrumb:false */}
      },
      {
        path: '/admin/course',
        component: () => import('@/views/course/index'),
        name: 'course',
        meta: { title: '课程管理', icon: 'education'}
      },
      {
        path: '/admin/chapter',
        component: () => import('@/views/chapter/index'),
        name: 'chapter',
        meta: { title: '章节管理', noCache: true },
        hidden: true
      },
      {
        path: '/admin/chapter_add',
        component: () => import('@/views/chapter/add'),
        name: 'chapter_add',
        meta: { title: '章节添加', noCache: true },
        hidden: true
      },
      {
        path: '/admin/article',
        component: () => import('@/views/article/index'),
        name: 'article',
        meta: { title: '文章资讯', icon: 'el-icon-notebook-2'}
      },
      {
        path: '/admin/article_add',
        component: () => import('@/views/article/add'),
        name: 'article_add',
        meta: { title: '文章添加', noCache: true },
        hidden: true
      },
      {
        path: '/admin/courseres',
        component: () => import('@/views/courseres/index'),
        name: 'courseres',
        meta: { title: '授课资源', icon: 'el-icon-document'}
      },
      {
        path: '/admin/courseres_add',
        component: () => import('@/views/courseres/add'),
        name: 'courseres_add',
        meta: { title: '资源添加', noCache: true },
        hidden: true
      }
    ]
  },
 {
    path: '/admin/goods-manage',
    component: Layout,
    alwaysShow: true,
    redirect: 'noRedirect',
    name: 'goods-manage',
    meta: {
      title: '日常管理',
      icon: 'el-icon-eleme'
    },
    children: [
      {
        path: '/admin/clock',
        component:  () => import('@/views/clock/index'),
        name: 'clock',
        meta: { title: '实时签到',icon: 'el-icon-view', noCache: true }
      }
    ]
  },
  /*
 {
    path: '/admin/promotion-manage',
    component: Layout,
    redirect: 'noRedirect',
    alwaysShow: true,
    name: 'promotion-manage',
    meta: { title: '校园招聘', icon: 'zip' },
    children: [
      {
        path: '/admin/activity',
        component: () => import('@/views/activity/index'),
        name: 'admin-activity',
        meta: { title: '招聘企业' }
      },
      {
        path: '/admin/activity_add',
        component: () => import('@/views/activity/add'),
        name: 'activity_add',
        meta: { title: '秒杀添加', noCache: true },
        hidden: true
      },
      {
        path: '/admin/activity_update',
        component: () => import('@/views/activity/add'),
        name: 'activity_update',
        meta: { title: '秒杀修改', noCache: true },
        hidden: true
      }
    ]
  },
  {
     path: '/admin/order-manage',
     component: Layout,
     redirect: 'noRedirect',
     alwaysShow: true,
     name: 'order-manage',
     meta: { title: '异地派遣', icon: 'zip' },
     children: [
       {
         path: '/admin/order',
         component: () => import('@/views/order/index'),
         name: 'admin-activity',
         meta: { title: '简历投递' }
       }
     ]
   }, */
  {
     path: '/admin/image',
     component: Layout,
     redirect: '/admin/image',
     children: [
       {
         path: '/admin/image',
         component: () => import('@/views/image/index'),
         name: 'admin-image',
         meta: { title: '图库管理', icon: 'el-icon-picture-outline', noCache: true }
       }
     ]
   },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
